package com.cmwa.solution.business.register.service.impl;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cmwa.solution.base.entity.Employee;
import com.cmwa.solution.base.entity.Page;
import com.cmwa.solution.base.entity.SearchParam;
import com.cmwa.solution.business.register.dao.SalesDataCheckDao;
import com.cmwa.solution.business.register.entity.CustCapitalChkVo;
import com.cmwa.solution.business.register.entity.CustInfoVo;
import com.cmwa.solution.business.register.entity.CustPortionChkVo;
import com.cmwa.solution.business.register.entity.CustTradeChkVo;
import com.cmwa.solution.business.register.entity.HomePageDataVo;
import com.cmwa.solution.business.register.service.SalesDataCheckService;
import com.cmwa.solution.utils.SessionUtils;
/**
 * 	销售数据对账业务层
 * @author ex-wuh2
 */
@Service
public class SalesDataCheckServiceImpl implements SalesDataCheckService {

	@Autowired
	private SalesDataCheckDao salesDataCheckDao;
	
	@Override
	public Page<CustInfoVo> queryCustInfoListPage(SearchParam sp) {
		List<CustInfoVo> items = salesDataCheckDao.queryCustInfoListPage(sp);
		return Page.create(items, sp.getStart(), sp.getLimit(), sp.getTotal());
	}

	@Override
	public Page<CustPortionChkVo> queryCustPortionListPage(SearchParam sp) {
		Employee emp = SessionUtils.getEmployee();
		if (StringUtils.equals(emp.getEmpType(), "OUT")) {
			sp.getSp().put("empId", emp.getID());
		}
		List<CustPortionChkVo> items = salesDataCheckDao.queryCustPortionListPage(sp);
		return Page.create(items, sp.getStart(), sp.getLimit(), sp.getTotal());
	}

	@Override
	public Page<CustTradeChkVo> queryCustTradeListPage(SearchParam sp) {
		Employee emp = SessionUtils.getEmployee();
		if (StringUtils.equals(emp.getEmpType(), "OUT")) {
			sp.getSp().put("empId", emp.getID());
		}
		List<CustTradeChkVo> items = salesDataCheckDao.queryCustTradeListPage(sp);
		return Page.create(items, sp.getStart(), sp.getLimit(), sp.getTotal());
	}

	@Override
	public Page<CustCapitalChkVo> queryCustCapitalChkListPage(SearchParam sp) {
		Employee emp = SessionUtils.getEmployee();
		if (StringUtils.equals(emp.getEmpType(), "OUT")) {
			sp.getSp().put("empId", emp.getID());
		}
		List<CustCapitalChkVo> items = salesDataCheckDao.queryCustCapitalChkListPage(sp);
		return Page.create(items, sp.getStart(), sp.getLimit(), sp.getTotal());
	}

	@Override
	public List<CustInfoVo> queryCustInfoList(String custname) {
		return salesDataCheckDao.queryCustInfoList(custname);
	}

	@Override
	public HomePageDataVo queryHomePageData(SearchParam sp) {
		return salesDataCheckDao.queryHomePageData(sp);
	}
}
